package org.example.livelock;

import lombok.extern.slf4j.Slf4j;
import org.example.utils.Sleeper;

/**
 * @author zhengdp
 * @Description 活锁问题
 * @Date 2022/10/30 19:45
 * @Created by zhengdp
 */
@Slf4j(topic = "c.LiveLock")
public class LiveLock {
    static volatile int count = 10;
    static  final  Object lock = new Object();
    public static void main(String[] args) {
        new Thread(() -> {
            // 期望减到0 退出循环
            while (count > 0){
                Sleeper.sleep(200);
                count --;
                log.info("count : {}",count);
            }
        },"t1").start();

        new Thread(() -> {
            // 期望超过20就退出循环
            while (count < 20){
                Sleeper.sleep(200);
                count ++;
                log.info("count : {}",count);
            }
        },"t2").start();

    }
}
